<?php
header('Content-Type:application/json');
$code=array("status"=>false,"msg"=>"","data"=>array());
if ($mysqli = new mysqli('localhost', 'songsong', '123456', 'sids')) {
    //echo 'good';
}
$mysqli->query('set names utf8');

$sno=$_GET["sNo"];
$name=$_GET["name"];
$sex=$_GET["sex"];
$class=$_GET["phone"];
$grade=$_GET["birth"];
$college=$_GET["email"];
$major=$_GET["address"];

//$major="计算机科学与技术";
$arr=Array("计算机科学与技术","网络工程","智能科学与技术","数据科学与大数据技术","空间信息与技术");
$isMajor=false;
for ($i=0;$i<count($arr);$i++){
    if($major==$arr[$i]) {
        $isMajor=true;
        break;
    }

}
if (!$isMajor){
    $code["msg"] = "没有此专业，修改失败！";
    $res = json_encode($code);
    echo $res;
    exit();
}
// $sno = '2018211463';
// $name = 'soot';
// $sex = '0';
// $class = '04911802';
// $grade = '2018';
// $college = NULL;
// $major = NULL;

$query = "select * from student where sno = '$sno'";
$result = $mysqli->query($query);
if ($result->num_rows > 0) {
    $code['status'] = true;
    $code['msg'] = 'found sno';
    //$code['data'] = $result->fetch_all(MYSQLI_BOTH);
    $update = "update student set 
        name ='$name', sex = '$sex', class = '$class', grade = '$grade', college = '$college', major ='$major'
        where sno = '$sno'";
    if($mysqli->query($update) === true) {
        $code['msg'] = 'edit success';
    }
}else {
    $code['status'] = false;
    $code['msg'] = "no such sno";
}
//$query = 'update'
$ret = json_encode($code);
echo $ret;
$mysqli->close();
?>